#ifndef __MEDIAFS_PCM_H__
#define __MEDIAFS_PCM_H__

#include <sndfile.h>
#include "converters.h"

#define MCTX_OUT_OF_BOUNDS 1

struct memory_io_ctx {
	char	*stream_contents;

	size_t	stream_size;
        size_t	stream_offset;
	
	int	flags;
};

struct sndfile_decoder_ctx {
        size_t		ctx_size;       
	char const 	*stream_contents;
	size_t		stream_size;

	struct		memory_io_ctx mem_ctx;
	SF_INFO		sf_info;
        SNDFILE		*sndfile;
};

struct sndfile_encoder_params {
	size_t	params_size;
	struct	mediafs_decoder_stat source_stat;
	int	format;
};
#define pcm_encoder_params sndfile_encoder_params

struct sndfile_encoder_ctx {
	size_t	ctx_size;
	struct mediafs_encoder *encoder;
	struct sndfile_encoder_params *params;

	char *header_buffer;
	size_t header_buffer_size;
	size_t header_size;

	struct memory_io_ctx mem_ctx;
	SNDFILE	*sndfile;
};

extern void fill_mediafs_pcm_encoder_params(struct pcm_encoder_params *_params, struct mediafs_decoder_stat *_decoder_stat);
extern struct mediafs_encoder *get_mediafs_pcm_encoder();
extern struct mediafs_decoder *get_mediafs_pcm_decoder();
extern struct mediafs_decoder *get_mediafs_flac_decoder();
extern void _init_ctx_sf_virtual_io(SF_VIRTUAL_IO *_vio);

#endif

